package com.hyperway.rpc.service;

import com.hyperway.rpc.client.IHelloService;
import com.hyperway.rpc.client.User;
import org.apache.dubbo.config.annotation.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * oauth2 demo 实现
 *
 * @author yanzhao
 * @date 2022/4/13 11:58
 * @since 1.0.0
 */
@Service(registry = "dubboRegistry", timeout = 3000, retries = 3, loadbalance = "random", actives = 5)
public class HelloService implements IHelloService {

    @Override
    public Object hello(String name) {
        return "Hello, " + name;
    }

    @Override
    public Object helloByte(Byte value) {
        Map<String, Object> r = new HashMap<>();
        r.put("value", value);
        return r;
    }

    @Override
    public Object helloShort(Short value) {
        Map<String, Object> r = new HashMap<>();
        r.put("value", value);
        return r;
    }

    @Override
    public Object helloInteger(Integer value) {
        Map<String, Object> r = new HashMap<>();
        r.put("value", value);
        return r;
    }

    @Override
    public Object helloLong(Long value) {
        Map<String, Object> r = new HashMap<>();
        r.put("value", value);
        return r;
    }

    @Override
    public Object helloFloat(Float value) {
        Map<String, Object> r = new HashMap<>();
        r.put("value", value);
        return r;
    }

    @Override
    public Object helloDouble(Double value) {
        Map<String, Object> r = new HashMap<>();
        r.put("value", value);
        return r;
    }

    @Override
    public Object helloBoolean(Boolean value) {
        Map<String, Object> r = new HashMap<>();
        r.put("value", value);
        return r;
    }

    @Override
    public Object helloString(String value) {
        Map<String, Object> r = new HashMap<>();
        r.put("value", value);
        return r;
    }

    @Override
    public Object helloUser(User value) {
        Map<String, Object> r = new HashMap<>();
        r.put("value", value);
        return r;
    }

    @Override
    public Object helloArray(User[] values) {
        return values;
    }

    @Override
    public Object helloList(List<User> values) {
        for (User value : values) {
            System.out.println(value);
        }
        return values;
    }

    @Override
    public Object helloStringList(List<String> values) {
        for (String value : values) {
            System.out.println(value);
        }
        return values;
    }

    @Override
    public Object helloMap(Map<String, User> values) {
        values.forEach((k, v) -> System.out.println(k + ":" + v));
        return values;
    }
}
